package com.example.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.constants.SystemConstants;
import com.example.domain.entity.Follow;
import com.example.domain.entity.Plant;
import com.example.domain.entity.User;
import com.example.exception.FloraException;
import com.example.service.IFollowService;
import com.example.service.impl.FollowServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zrr
 * @since 2022-12-02
 */
@RestController
@RequestMapping("/follow")
public class FollowController {
    @Autowired
    IFollowService followService;

    @GetMapping("/getFollowingListOfPlant/{followerId}")
    public IPage<Plant> getFollowingListOfPlant(@PathVariable long followerId, @RequestParam(defaultValue = "0") Integer pageNum,
                                                @RequestParam (defaultValue = "10")Integer pageSize){
        return followService.getFollowingList(followerId, SystemConstants.FOLLOW_TYPE_PLANT,pageNum,pageSize);
    }

    @GetMapping("/getFollowingListOfUser/{followerId}")
    public IPage<User> getFollowingListOfUser(@PathVariable long followerId, @RequestParam (defaultValue = "0") Integer pageNum,
                                              @RequestParam (defaultValue = "10") Integer pageSize){
        return followService.getFollowingList(followerId,SystemConstants.FOLLOW_TYPE_USER,pageNum,pageSize);
    }

    @GetMapping("/followerNumOfPlant/{plantId}")
    public Long getFollowerNumOfPlant(@PathVariable long plantId){
        return followService.getFollowerNumOfPlant(plantId);
    }

    @GetMapping("/followerNumOfUser/{userId}")
    public Long getFollowerNumOfUser(@PathVariable long userId){
        return followService.getFollowerNumOfUser(userId);
    }

    @PostMapping("/addFollowerOfPlant")
    public void addFollowerOfPlant(@RequestBody Follow follow)throws FloraException {
        followService.addFollowerOfPlant(follow);
    }

    @PostMapping("/addFollowerOfUser")
    public void addFollowerOfUser(@RequestBody Follow follow)throws FloraException {
        followService.addFollowerOfUser(follow);
    }

    @DeleteMapping("/deleteFollowerOfPlant")
    public void deleteFollowerOfPlant(@RequestBody Follow follow){
        followService.deleteFollowerOfPlant(follow);
    }

    @DeleteMapping("/deleteFollowerOfUser")
    public void deleteFollowerOfUser(@RequestBody Follow follow){
        followService.deleteFollowerOfUser(follow);
    }
}

